/
EventLogServiceController.cs
77 lines (69 loc) · 2.77 KB
/
EventLogServiceController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Web.InternalServices
{
using System;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Web;
using System.Web.Http;
using DotNetNuke.Instrumentation;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Log.EventLog;
using DotNetNuke.Web.Api;
[DnnAuthorize]
public class EventLogServiceController : DnnApiController
{
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(EventLogServiceController));
[HttpGet]
[DnnAuthorize(StaticRoles = "Administrators")]
public HttpResponseMessage GetLogDetails(string guid)
{
Guid logId;
if (string.IsNullOrEmpty(guid) || !Guid.TryParse(guid, out logId))
{
return this.Request.CreateResponse(HttpStatusCode.BadRequest);
}
try
{
if (!(EventLogController.Instance.GetLog(guid) is LogInfo logInfo))
{
return this.Request.CreateResponse(HttpStatusCode.BadRequest);
}
return this.Request.CreateResponse(HttpStatusCode.OK, new
{
Title = Localization.GetSafeJSString("CriticalError.Error", Localization.SharedResourceFile),
Content = this.GetPropertiesText(logInfo),
});
}
catch (Exception ex)
{
Logger.Error(ex);
return this.Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
private string GetPropertiesText(LogInfo logInfo)
{
var objLogProperties = logInfo.LogProperties;
var str = new StringBuilder();
int i;
for (i = 0; i <= objLogProperties.Count - 1; i++)
{
// display the values in the Panel child controls.
var ldi = (LogDetailInfo)objLogProperties[i];
if (ldi.PropertyName == "Message")
{
str.Append("<p><strong>" + ldi.PropertyName + "</strong>:</br><pre>" + HttpUtility.HtmlEncode(ldi.PropertyValue) + "</pre></p>");
}
else
{
str.Append("<p><strong>" + ldi.PropertyName + "</strong>:" + HttpUtility.HtmlEncode(ldi.PropertyValue) + "</p>");
}
}
str.Append("<p><b>Server Name</b>: " + HttpUtility.HtmlEncode(logInfo.LogServerName) + "</p>");
return str.ToString();
}
}
}